#include <CUnit/CUnit.h>
#include <CUnit/Basic.h>
#include <CUnit/Automated.h>
#include <CUnit/Console.h>

#include <stdlib.h>
#include "zip_utils.h"
#include "zip_domain_wblist.h"

void traverse_print(void *data)
{
    if (data)
        printf("address is %p\n", data);
}
static void test_domain_wblist()
{
    domain_wblist_t *domain_wblist = domain_wblist_create();
    CU_ASSERT_TRUE(domain_wblist != NULL);
    
    int ret = domain_wblist_insert_from_text(domain_wblist, "www.baidu.com");
    CU_ASSERT_TRUE(ret == 0);
    CU_ASSERT_EQUAL(domain_wblist_get_count(domain_wblist), 1);

    wire_name_t *wire_name = wire_name_from_text("www.baidu.com");
    CU_ASSERT_TRUE(wire_name != NULL);

    ret = domain_wblist_insert_from_wire(domain_wblist, wire_name);
    CU_ASSERT_TRUE(ret != 0);
    CU_ASSERT_EQUAL(domain_wblist_get_count(domain_wblist), 1);

    ret = domain_wblist_find_from_wire(domain_wblist, wire_name);
    CU_ASSERT_TRUE(ret == 0);

    printf("count %d\n", domain_wblist_get_count(domain_wblist));
    ret = domain_wblist_delete_from_wire(domain_wblist, wire_name);
    CU_ASSERT_TRUE(ret == 0);
    printf("count %d\n", domain_wblist_get_count(domain_wblist));
    CU_ASSERT_EQUAL(domain_wblist_get_count(domain_wblist), 0);

    ret = domain_wblist_insert_from_text(domain_wblist, "www.google.com");
    CU_ASSERT_TRUE(ret == 0);
    CU_ASSERT_EQUAL(domain_wblist_get_count(domain_wblist), 1);

    ret = domain_wblist_delete_from_text(domain_wblist, "www.baidu.com");
    CU_ASSERT_TRUE(ret != 0);
    CU_ASSERT_EQUAL(domain_wblist_get_count(domain_wblist), 1);

    ret = domain_wblist_find_from_text(domain_wblist, "www.google.com");
    CU_ASSERT_TRUE(ret == 0);

    ret = domain_wblist_insert_from_text(domain_wblist, "www.google.com");
    CU_ASSERT_TRUE(ret != 0);
    CU_ASSERT_EQUAL(domain_wblist_get_count(domain_wblist), 1);

    ret = domain_wblist_insert_from_text(domain_wblist, "www.baidu.com");
    CU_ASSERT_TRUE(ret == 0);
    CU_ASSERT_EQUAL(domain_wblist_get_count(domain_wblist), 2);

    domain_wblist_destroy(domain_wblist);

}
static CU_TestInfo domain_wblist_tests[] = {
    {"domain_wblist_test", test_domain_wblist},
    CU_TEST_INFO_NULL,
};

static CU_SuiteInfo  first_suit[] = {
    {"domain_wblist_tests", NULL, NULL, domain_wblist_tests},
    CU_SUITE_INFO_NULL,
};

int main()
{
    CU_BasicRunMode mode = CU_BRM_VERBOSE;
    CU_ErrorAction error_action = CUEA_FAIL;

    CU_initialize_registry();
    CU_register_suites(first_suit);
    CU_basic_set_mode(mode);
    CU_set_error_action(error_action);
    CU_basic_run_tests();
    CU_cleanup_registry();
    return 0;
}


